#pragma once
#include "DirectoryListing.h"
#include "DirectoryEntryWithTree.h"
#include "gstring.h"
#include <list>
using namespace std;

class DirectoryEntryWithTree; // This line is put here to resolve a circular class reference.

/// <summary>
/// Gets a directory listing and recurse into subdirectories. Differentiates between files and folders.
/// </summary>
class DirectoryTree
{
public:
	/// <summary>
	/// The folder this directory listing is for. Unless it's the root folder, it shouldn't contain \\ or //
	/// </summary>
	gstring Folder;
	/// <summary>
	/// List of files in this folder.
	/// </summary>
	list<DirectoryEntry*> Files;
	/// <summary>
	/// List of subfolders in this folder.
	/// </summary>
	list <DirectoryTree*> Folders;
	/// <summary>
	/// The DirectoryTree item of the parent folder. Parent->Folders should contain "this". If NULL then this is the root of the tree.
	/// </summary>
	DirectoryTree* Parent;
	/// <summary>
	/// How fast from 0 to 100. If Speed < 100 Then Sleep(99-Speed).
	/// </summary>
	int Speed;
	/// <summary>
	/// Constructor
	/// </summary>
	DirectoryTree();
	/// <summary>
	/// Destructor
	/// </summary>
	~DirectoryTree();
	/// <summary>
	/// Clears all the Files and Folders.
	/// </summary>
	void Clear();
	/// <summary>
	/// Reads the directory and fills Files and Folders.
	/// </summary>
	/// <param name="recursive">If recursive is set to true, then Folders will have their directories read too.</param>
	void ReadDirectory(bool recursive);
	/// <summary>
	/// Returns the full path of this directory with the fileName appended in output.
	/// </summary>
	/// <param name="fileName">File name suffix</param>
	/// <param name="output">Changes output to be the full path.</param>
	void GetFullPath(const gstring *fileName,gstring &output);
	/// <summary>
	/// Follows Parent all the way down until it finds the first DirectoryTree where Parent == NULL.
	/// </summary>
	/// <returns>first DirectoryTree where Parent == NULL</returns>
	DirectoryTree *GrandParent();
	/// <summary>
	/// Returns the number of files.
	/// </summary>
	/// <param name="recurseFolders">If recurseFolders, then count all files in all folders.</param>
	/// <returns>Returns the number of files.</returns>
	int FileCount(bool recurseFolders);
};
